#!/bin/bash
server="raftserver"
method=$1
addr=$2
name=$3
addr2=$4
# your need to install `curl` before use this script

function Begin() {
  curl -X POST "http://${addr}/${server}/control/Begin" -H 'content-type: application/json' -d '{"SessionId": "random_string"}'
}

function Register() {
  curl -X POST "http://${addr}/${server}/Register" -H 'content-type: application/json' -d "{\"Addr\": ${addr2}, \"Name\": ${name}}"
}

if [ ${method} = "begin" ]; then
  Begin
fi

if [ ${method} = "register" ]; then
  Register
fi